package borge.web.teamspirit.client.servercomm;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


public class DBQueryResult<T extends Serializable> implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private boolean iSuccess;
    private String iErrorMsg;
    private List<T> iResultList;
    private DBQueryResult<T> iNext;
    
    public DBQueryResult(){
        
    }
    // When we fail
    public DBQueryResult(String aErrorMsg){
        iSuccess = false;
        iErrorMsg = aErrorMsg;
    }
    
    public DBQueryResult(List<T> aList){
        iSuccess = true;
        iResultList = aList;
    }
    
    public DBQueryResult(boolean status){
        iSuccess = status;
    }
    
    public void addObject(T aObject){
    	if(iResultList == null)
    		iResultList = new ArrayList<T>();
    	
    	iResultList.add(aObject);
    }
    
    public void setSuccess(boolean aSuccess){
    	iSuccess = aSuccess;
    }
    
    public boolean hasObjects(){
    	return iResultList != null && iResultList.size() > 0;
    }
    
    public boolean queryFailed(){
        return !iSuccess;
    }
    
    public boolean getBooleanState(){
    	return iSuccess;
    }
    
    public String getErrorMsg(){
        return iErrorMsg;
    }
    
    public List<T> getResultList(){
        return iResultList;
    }
    
    public DBQueryResult<T> setNext(DBQueryResult<T> result){
    	iNext = result;
    	return iNext;
    }
    
    public DBQueryResult<T> getNext(){
    	return iNext;
    }
    
}
